﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.IO;
using BarCode.Common;
using System.Runtime.InteropServices;
using BarCode.Bean;

namespace BarCode.Module
{

    public class BarCodePrint
    {
        public static void PrintBarCode(PrintBarCodeInfo printInfo)
        {
            // 10/21 微信 修改为 包含“合肥燃气”
            //if ("合肥燃气集团".Equals(printInfo.strCustomer))
            if (printInfo.strCustomer.Contains("合肥燃气"))
            {
                // 2018/11/26 合肥打印两次 修改 
                PrintBarCodeHF(printInfo);
                PrintBarCodeHF(printInfo);
                return;
            }
            // 20190704 Add
            else if (printInfo.strCustomer.StartsWith("沈阳燃气公司"))
            {
                PrintBarCodeSY(printInfo);
                return;
            }
            // 20190915 Add
            else if (printInfo.strCustomer.StartsWith("安阳计量站"))
            {
                PrintBarCodeAY(printInfo);
                return;
            }
           

            // 2021.12.05 Add 铜陵港华打印两份
            if (printInfo.strCustomer.StartsWith("铜陵港华"))
            {
                printInfo.strPrtNum = 2;
            }
            // 20220811 Add 淄博华润打印两份
            else if (printInfo.strCustomer.StartsWith("淄博华润"))
            {
                printInfo.strPrtNum = 2;
            }

            if (printInfo.intModel == 1)
            {
                //PrintBarCode1Max(printInfo);
                PrintBarCode1(printInfo);
            }
            else if (printInfo.intModel == 2)
            {
                PrintBarCode2(printInfo);
            }

        }

        /// <summary>
        /// 合肥打印
        /// </summary>
        /// <param name="printInfo"></param>
        private static void PrintBarCodeHF(PrintBarCodeInfo printInfo)
        {

            int xStart, yStart, xDist, yDist, fontDist, xFont, yFont, yfontDist, xBar, fontsize, fontsize1;
            string cmdBox, cmdQrcode, qrCodeContent, weight;

            fontsize = 45;
            fontsize1 = 50;
            xStart = 24;
            yStart = 30 + printInfo.intDist;
            xDist = 50;
            xFont = xStart + 90;

            yDist = 220;
            yFont = 72;

            fontDist = 400;
            TSCLIB_DLL.openport(printInfo.strPrtName);

            TSCLIB_DLL.setup("80", "65", "2", Consts.PRINT_DENSITY, "0", "4", "0");

            TSCLIB_DLL.clearbuffer();

            TSCLIB_DLL.sendcommand("BACKFEED 360");

            string title = "";
            if (("正向").Equals(printInfo.mDirections))
            {
                title = "膜式燃气表（左进气）";
            }
            else if (("反向").Equals(printInfo.mDirections))
            {
                title = "膜式燃气表（右进气）";
            }
            else
            {
                title = "膜式燃气表";
            }

            TSCLIB_DLL.windowsfont(xStart, yStart + 640, 55, 90, 2, 0, "宋体", title);


            // 画框
            cmdBox = "BOX 96," + yStart + ",412," + (yStart + 360) + ",2";
            TSCLIB_DLL.sendcommand(cmdBox);
            cmdBox = "BOX 96," + (yStart + 360) + ",412," + (yStart + 720) + ",2";
            TSCLIB_DLL.sendcommand(cmdBox);

            // 条码
            qrCodeContent = "";
            // 2019/05/18 合肥公司修改二维码内容
            //for (int i = 0; i <= printInfo.intCount - 1; i++)
            //{
            //    TSCLIB_DLL.windowsfont((xFont + i * xDist), 720, fontsize, 90, 0, 0, "黑体", printInfo.strCode[i]);
            //    qrCodeContent = qrCodeContent + printInfo.strCode[i];
            //    if (i < printInfo.intCount - 1)
            //    {
            //        qrCodeContent = qrCodeContent + Environment.NewLine;
            //    }
            //}
            for (int i = 0; i <= printInfo.intCount - 1; i++)
            {
                TSCLIB_DLL.windowsfont((xFont + i * xDist), 720, fontsize, 90, 0, 0, "黑体", printInfo.strCode[i]);
                // 1021 微信 分隔改成换行符
                //qrCodeContent = qrCodeContent + printInfo.strCode[i] + ",";
                if (i == printInfo.intCount - 1)
                {
                    // 最后一个不需要换行符
                    qrCodeContent = qrCodeContent + printInfo.strCode[i];
                }
                else
                {
                    qrCodeContent = qrCodeContent + printInfo.strCode[i] + Environment.NewLine;
                }
            }

            TSCLIB_DLL.windowsfont((xFont + 0 * xDist), (yStart + 348), fontsize, 90, 0, 0, "宋体", "型号：" + printInfo.mType);
            TSCLIB_DLL.windowsfont((xFont + 1 * xDist), (yStart + 348), fontsize, 90, 0, 0, "宋体", "数量：" + printInfo.packCount + " 只");
            if (printInfo.packCount == 4)
            {
                weight = "9.8 kg";
            }
            else
            {

            } weight = "10.8 kg";


            TSCLIB_DLL.windowsfont((xFont + 2 * xDist), (yStart + 348), fontsize, 90, 0, 0, "宋体", "毛重：" + weight);
            TSCLIB_DLL.windowsfont((xFont + 3 * xDist), (yStart + 348), fontsize, 90, 0, 0, "宋体", "生产日期：");
            TSCLIB_DLL.windowsfont((xFont + 4 * xDist), (yStart + 348), fontsize, 90, 0, 0, "宋体", printInfo.productDate.ToString("D"));


            TSCLIB_DLL.windowsfont((xStart + 400), (yStart + 680), 50, 90, 0, 0, "宋体", "识别号/客户：" + printInfo.strCustomer);

            cmdQrcode = "QRCODE " + (xStart + 474) + "," + (yStart + 244) + @",Q,7,A,0,M2,S7,""" + qrCodeContent + @"""";
            TSCLIB_DLL.sendcommand(cmdQrcode);


            TSCLIB_DLL.windowsfont((xStart + 546), (yStart + 190), 60, 90, 2, 0, "宋体", "保证");
            TSCLIB_DLL.windowsfont((xStart + 618), (yStart + 190), 60, 90, 2, 0, "宋体", "读取");

            TSCLIB_DLL.windowsfont((xStart + 546), (yStart + 682), 60, 90, 2, 0, "宋体", "请勿");
            TSCLIB_DLL.windowsfont((xStart + 618), (yStart + 682), 60, 90, 2, 0, "宋体", "磨损");

            // 封箱号
            TSCLIB_DLL.windowsfont((xStart + 786), (yStart + 526), 50, 90, 2, 0, "宋体", printInfo.packCode);
            TSCLIB_DLL.windowsfont((xStart + 848), (yStart + 696), 50, 90, 2, 0, "宋体", "荣成市宇翔实业有限公司制造");

            TSCLIB_DLL.printlabel("1", printInfo.strPrtNum.ToString());

            TSCLIB_DLL.sendcommand("FEED 360");

            TSCLIB_DLL.closeport();
        }

        /// <summary>
        /// 标准
        /// </summary>
        /// <param name="printInfo"></param>
        private static void PrintBarCodeSY(PrintBarCodeInfo printInfo)
        {

            int xStart, yStart, xDist, yDist, fontDist, xFont, yFont, yfontDist, xBar;
            int fontsize, fontsize1;
            string cmdBox;

            fontsize = 55;
            fontsize1 = 50;

            xStart = 80;
            yStart = 415 + printInfo.intDist;
            xDist = 80;
            xFont = 250 + 70;

            yDist = 220;
            yFont = 72;

            fontDist = 400;
            TSCLIB_DLL.openport(GlobalVal.ipAddressInfo.PRINTER_NAME);

            TSCLIB_DLL.setup("60", "40", "2", Consts.PRINT_DENSITY, "0", "4", "0");

            TSCLIB_DLL.clearbuffer();

            TSCLIB_DLL.sendcommand("BACKFEED 360");

            string qrCodeContent = "";
            for (int i = 0; i < printInfo.intCount; i++)
            {
                if (printInfo.strCode[i].Length > 12)
                {
                    TSCLIB_DLL.windowsfont(xFont + i * xDist + 5, yStart - 10, fontsize - 10, 90, 2, 0, "黑体", printInfo.strCode[i]);
                }
                else
                {
                    TSCLIB_DLL.windowsfont(xFont + i * xDist + 5, yStart - 10, fontsize, 90, 2, 0, "黑体", printInfo.strCode[i]);
                }
                qrCodeContent += printInfo.strCode[i] + "/";
            }
            qrCodeContent = qrCodeContent.Remove(qrCodeContent.Length - 1);

            cmdBox = "BOX 290," + Convert.ToString(yStart - 370) + ",680," + Convert.ToString(yStart + 70) + ",2";
            TSCLIB_DLL.sendcommand(cmdBox);

            TSCLIB_DLL.windowsfont(xFont + 5, yStart + 50, fontsize1, 90, 2, 0, "宋体", "装");
            TSCLIB_DLL.windowsfont(xFont + xDist, yStart + 50, fontsize1, 90, 2, 0, "宋体", "箱");
            TSCLIB_DLL.windowsfont(xFont + xDist * 2, yStart + 50, fontsize1, 90, 2, 0, "宋体", "明");
            TSCLIB_DLL.windowsfont(xFont + xDist * 3, yStart + 50, fontsize1, 90, 2, 0, "宋体", "细");



            //TSCLIB_DLL.barcode(Convert.ToString(xStart - 50), Convert.ToString(yStart + 50), "128", "150", "0", "270", "4", "4", printInfo.packCode);
            TSCLIB_DLL.windowsfont(xFont - 80, yStart + 10, 50, 90, 2, 0, "黑体", printInfo.packCode);

            string cmdQrcode = "QRCODE " + (xStart - 50) + "," + (yStart - 244) + @",Q,7,A,0,M2,S7,""" + qrCodeContent + @"""";
            TSCLIB_DLL.sendcommand(cmdQrcode);

            //if (printInfo.strCustomer.Length <= 6)
            //{
            //    TSCLIB_DLL.windowsfont(xStart + 540, yStart + 50, 65, 90, 2, 0, "宋体", printInfo.strCustomer);
            //}
            //else
            //{
            //    TSCLIB_DLL.windowsfont(xStart + 540, yStart + 70, 45, 90, 2, 0, "宋体", printInfo.strCustomer);
            //}


            TSCLIB_DLL.printlabel("1", printInfo.strPrtNum.ToString());

            TSCLIB_DLL.sendcommand("FEED 360");

            TSCLIB_DLL.closeport();
        }


        /// <summary>
        /// 安阳计量站
        /// </summary>
        /// <param name="printInfo"></param>
        private static void PrintBarCodeAY(PrintBarCodeInfo printInfo)
        {

            int xStart, yStart, xDist, xFont;
            int fontsize;

            fontsize = 45;

            xStart = 110;
            yStart = 420 + printInfo.intDist;
            xDist = 140;
            xFont = xStart + 70;

            TSCLIB_DLL.openport(GlobalVal.ipAddressInfo.PRINTER_NAME);

            TSCLIB_DLL.setup("60", "40", "2", Consts.PRINT_DENSITY, "0", "4", "0");

            TSCLIB_DLL.clearbuffer();

            TSCLIB_DLL.sendcommand("BACKFEED 360");

            // 打印箱号
            TSCLIB_DLL.windowsfont(xStart - 75, yStart + 60, fontsize, 90, 2, 0, "黑体", "箱号:" + printInfo.packCode);

            for (int i = 0; i < printInfo.intCount; i++)
            {
                TSCLIB_DLL.barcode(Convert.ToString(xStart + i * xDist), Convert.ToString(yStart), "128", "75", "0", "270", "3", "3", printInfo.strCode[i]);
                TSCLIB_DLL.windowsfont(xFont + i * xDist, yStart - 10, fontsize, 90, 2, 0, "黑体", printInfo.strCode[i]);
            }

            TSCLIB_DLL.printlabel("1", printInfo.strPrtNum.ToString());

            TSCLIB_DLL.sendcommand("FEED 360");

            TSCLIB_DLL.closeport();
        }



        /// <summary>
        /// 标准
        /// </summary>
        /// <param name="printInfo"></param>
        private static void PrintBarCode1(PrintBarCodeInfo printInfo)
        {
            if (printInfo.driveMode)
            {
                // 有传动方式

                int xStart, yStart, xDist, xFont;
                int fontsize, fontsize1;
                string cmdBox;

                fontsize = 52;
                fontsize1 = 45;

                xStart = 80;
                yStart = 410 + printInfo.intDist;
                xDist = 55;
                xFont = 270 + 10;

                TSCLIB_DLL.openport(GlobalVal.ipAddressInfo.PRINTER_NAME);

                TSCLIB_DLL.setup("60", "40", "2", Consts.PRINT_DENSITY, "0", "4", "0");

                TSCLIB_DLL.clearbuffer();

                TSCLIB_DLL.sendcommand("BACKFEED 360");


                TSCLIB_DLL.barcode(Convert.ToString(xStart - 65), Convert.ToString(yStart + 55), "128", "90", "0", "270", "4", "4", printInfo.packCode);
                TSCLIB_DLL.windowsfont(xStart + 20, yStart + 35, 55, 90, 2, 0, "黑体", printInfo.packCode);

                TSCLIB_DLL.windowsfont(xStart + 90 - 10, yStart + 60, 35, 90, 0, 0, "宋体", "型号:");
                TSCLIB_DLL.windowsfont(xStart + 85 - 15, yStart - 40, 50, 90, 2, 0, "黑体", printInfo.mType);
                TSCLIB_DLL.windowsfont(xStart + 90 - 10, yStart - 200, 35, 90, 0, 0, "宋体", "数量:");
                TSCLIB_DLL.windowsfont(xStart + 85 - 15, yStart - 300, 50, 90, 2, 0, "黑体", printInfo.packCount.ToString());

                xStart = xStart + 10;
                TSCLIB_DLL.windowsfont(xStart + 115, yStart + 60, 35, 90, 0, 0, "宋体", "传动方式:");
                TSCLIB_DLL.windowsfont(xStart + 112, yStart - 100, 35, 90, 2, 0, "黑体", "磁传动");

                TSCLIB_DLL.windowsfont(xStart + 130 + 25, yStart + 60, 35, 90, 0, 0, "宋体", "出厂日期:");
                TSCLIB_DLL.windowsfont(xStart + 125 + 25, yStart - 100, 40, 90, 2, 0, "黑体", printInfo.productDate.ToString("yyyyMMdd"));

                xFont = xFont + 10;
                for (int i = 0; i < printInfo.intCount; i++)
                {
                    if (printInfo.strCode[i].Length > 12)
                    {
                        TSCLIB_DLL.windowsfont(xFont + i * xDist, yStart - 10, fontsize - 20, 90, 2, 0, "黑体", printInfo.strCode[i]);
                    }
                    else
                    {
                        TSCLIB_DLL.windowsfont(xFont + i * xDist, yStart - 10, fontsize, 90, 2, 0, "黑体", printInfo.strCode[i]);
                    }

                }

                cmdBox = "BOX 290," + Convert.ToString(yStart - 370) + ",615," + Convert.ToString(yStart + 70) + ",2";
                TSCLIB_DLL.sendcommand(cmdBox);

                TSCLIB_DLL.windowsfont(xFont + 5 + 0, yStart + 55, fontsize1, 90, 2, 0, "宋体", "装");
                TSCLIB_DLL.windowsfont(xFont + 5 + xDist, yStart + 55, fontsize1, 90, 2, 0, "宋体", "箱");
                TSCLIB_DLL.windowsfont(xFont + 5 + xDist * 2, yStart + 55, fontsize1, 90, 2, 0, "宋体", "明");
                TSCLIB_DLL.windowsfont(xFont + 5 + xDist * 3, yStart + 55, fontsize1, 90, 2, 0, "宋体", "细");

                //if (printInfo.strCustomer.Length <= 6)
                //{
                //    TSCLIB_DLL.windowsfont(xStart + 540, yStart + 50, 65, 90, 2, 0, "宋体", printInfo.strCustomer);
                //}
                //else
                //{
                //    TSCLIB_DLL.windowsfont(xStart + 540, yStart + 70, 42, 90, 2, 0, "宋体", printInfo.strCustomer);
                //}
                TSCLIB_DLL.windowsfont(xStart + 540, yStart + 70, 42, 90, 2, 0, "宋体", printInfo.strCustomer);

                TSCLIB_DLL.printlabel("1", printInfo.strPrtNum.ToString());

                TSCLIB_DLL.sendcommand("FEED 360");

                TSCLIB_DLL.closeport();
            }
            else
            {
                // 没有传动方式，以前的打印
                int xStart, yStart, xDist, xFont;
                int fontsize, fontsize1;
                string cmdBox;

                fontsize = 52;
                fontsize1 = 45;

                xStart = 80;
                yStart = 410 + printInfo.intDist;
                xDist = 55;
                xFont = 270;

                TSCLIB_DLL.openport(GlobalVal.ipAddressInfo.PRINTER_NAME);

                TSCLIB_DLL.setup("60", "40", "2", Consts.PRINT_DENSITY, "0", "4", "0");

                TSCLIB_DLL.clearbuffer();

                TSCLIB_DLL.sendcommand("BACKFEED 360");



                TSCLIB_DLL.barcode(Convert.ToString(xStart - 65), Convert.ToString(yStart + 55), "128", "90", "0", "270", "4", "4", printInfo.packCode);
                TSCLIB_DLL.windowsfont(xStart + 20, yStart + 35, 55, 90, 2, 0, "黑体", printInfo.packCode);

                TSCLIB_DLL.windowsfont(xStart + 90, yStart + 60, 35, 90, 0, 0, "宋体", "型号:");
                TSCLIB_DLL.windowsfont(xStart + 80, yStart - 40, 50, 90, 2, 0, "黑体", printInfo.mType);
                TSCLIB_DLL.windowsfont(xStart + 90, yStart - 200, 35, 90, 0, 0, "宋体", "数量:");
                TSCLIB_DLL.windowsfont(xStart + 80, yStart - 300, 50, 90, 2, 0, "黑体", printInfo.packCount.ToString());

                TSCLIB_DLL.windowsfont(xStart + 135, yStart + 60, 35, 90, 0, 0, "宋体", "出厂日期:");
                TSCLIB_DLL.windowsfont(xStart + 130, yStart - 100, 45, 90, 2, 0, "黑体", printInfo.productDate.ToString("yyyyMMdd"));

                for (int i = 0; i < printInfo.intCount; i++)
                {
                    if (printInfo.strCode[i].Length > 12)
                    {
                        TSCLIB_DLL.windowsfont(xFont + i * xDist, yStart - 10, fontsize - 20, 90, 2, 0, "黑体", printInfo.strCode[i]);
                    }
                    else
                    {
                        TSCLIB_DLL.windowsfont(xFont + i * xDist, yStart - 10, fontsize, 90, 2, 0, "黑体", printInfo.strCode[i]);
                    }

                }

                cmdBox = "BOX 270," + Convert.ToString(yStart - 370) + ",610," + Convert.ToString(yStart + 70) + ",2";
                TSCLIB_DLL.sendcommand(cmdBox);

                TSCLIB_DLL.windowsfont(xFont + 5 + 0, yStart + 55, fontsize1, 90, 2, 0, "宋体", "装");
                TSCLIB_DLL.windowsfont(xFont + 5 + xDist, yStart + 55, fontsize1, 90, 2, 0, "宋体", "箱");
                TSCLIB_DLL.windowsfont(xFont + 5 + xDist * 2, yStart + 55, fontsize1, 90, 2, 0, "宋体", "明");
                TSCLIB_DLL.windowsfont(xFont + 5 + xDist * 3, yStart + 55, fontsize1, 90, 2, 0, "宋体", "细");

                //if (printInfo.strCustomer.Length <= 6)
                //{
                //    TSCLIB_DLL.windowsfont(xStart + 540, yStart + 50, 65, 90, 2, 0, "宋体", printInfo.strCustomer);
                //}
                //else
                //{
                //    TSCLIB_DLL.windowsfont(xStart + 540, yStart + 70, 42, 90, 2, 0, "宋体", printInfo.strCustomer);
                //}
                TSCLIB_DLL.windowsfont(xStart + 540, yStart + 70, 42, 90, 2, 0, "黑体", printInfo.strCustomer);

                TSCLIB_DLL.printlabel("1", printInfo.strPrtNum.ToString());

                TSCLIB_DLL.sendcommand("FEED 360");

                TSCLIB_DLL.closeport();
            }
            
        }

        /// <summary>
        /// 标准
        /// </summary>
        /// <param name="printInfo"></param>
        private static void PrintBarCode2(PrintBarCodeInfo printInfo)
        {

            int xStart, yStart, xDist, yDist, fontDist, xFont, yFont, yfontDist, xBar;
            int fontsize, fontsize1;
            string cmdBox;

            fontsize = 46;
            fontsize1 = 42;

            xStart = 80;
            yStart = 410 + printInfo.intDist;
            xDist = 50;
            xFont = 20;

            yDist = 220;
            yFont = 72;
            xBar = (600 / printInfo.intCount - 50);

            fontDist = 400;
            TSCLIB_DLL.openport(GlobalVal.ipAddressInfo.PRINTER_NAME);

            TSCLIB_DLL.setup("60", "40", "2", Consts.PRINT_DENSITY, "0", "4", "0");

            TSCLIB_DLL.clearbuffer();

            TSCLIB_DLL.sendcommand("BACKFEED 360");

            for (int i = 0; i < printInfo.intCount; i++)
            {
                TSCLIB_DLL.barcode(Convert.ToString(xFont + i * (xDist + xBar)), Convert.ToString(yStart - 70), "128", Convert.ToString(xBar + 2), "0", "270", "3", "4", printInfo.strCode[i]); //打印表号条码
                TSCLIB_DLL.windowsfont((xFont + i * (xDist + xBar) + xBar - 3), (yStart - 70), fontsize1, 90, 2, 0, "黑体", printInfo.strCode[i]); //打印表号
            }

            //cmdBox = "BOX 250," + Convert.ToString(yStart - 370) + ",610," + Convert.ToString(yStart + 70) + ",2";
            //TSCLIB_DLL.sendcommand(cmdBox);

            TSCLIB_DLL.barcode(Convert.ToString(xStart - 30), Convert.ToString(yStart - 55), "128", "70", "0", "0", "4", "4", printInfo.packCode);      // 打印封箱条码
            TSCLIB_DLL.windowsfont((xStart + 20), (yStart + 15), fontsize, 0, 2, 0, "黑体", printInfo.packCode);      // 打印箱号

            TSCLIB_DLL.windowsfont((xStart + 540), (yStart + 50), 65, 90, 2, 0, "宋体", printInfo.strCustomer);

            TSCLIB_DLL.printlabel("1", printInfo.strPrtNum.ToString());

            TSCLIB_DLL.sendcommand("FEED 360");

            TSCLIB_DLL.closeport();
        }


        /// <summary>
        /// 标准 大标签纸 80*65
        /// </summary>
        /// <param name="printInfo"></param>
        private static void PrintBarCode1Max(PrintBarCodeInfo printInfo)
        {
            if (printInfo.driveMode)
            {
                // 有传动方式
                int xStart, yStart, xDist, xFont;
                int fontsize, fontsize1;
                string cmdBox;

                fontsize = 52;
                fontsize1 = 45;

                xStart = 100;
                //yStart = 610 + printInfo.intDist;
                xDist = 120;
                xFont = 380;

                TSCLIB_DLL.openport(GlobalVal.ipAddressInfo.PRINTER_NAME);

                TSCLIB_DLL.setup("80", "65", "2", Consts.PRINT_DENSITY, "0", "4", "0");

                TSCLIB_DLL.clearbuffer();

                TSCLIB_DLL.sendcommand("BACKFEED 360");

                yStart = 550 + printInfo.intDist;
                TSCLIB_DLL.barcode(Convert.ToString(xStart - 65), Convert.ToString(yStart + 115), "128", "90", "2", "270", "5", "5", printInfo.packCode);
                //TSCLIB_DLL.windowsfont(xStart + 20, yStart + 35, 55, 90, 2, 0, "黑体", printInfo.packCode);

                TSCLIB_DLL.windowsfont(xStart + 80, yStart + 110, 40, 90, 0, 0, "宋体", "型号:");
                TSCLIB_DLL.windowsfont(xStart + 60, yStart, 75, 90, 2, 0, "黑体", printInfo.mType);
                TSCLIB_DLL.windowsfont(xStart + 80, yStart - 230, 40, 90, 0, 0, "宋体", "数量:");
                TSCLIB_DLL.windowsfont(xStart + 60, yStart - 340, 75, 90, 2, 0, "黑体", printInfo.packCount.ToString());


                TSCLIB_DLL.windowsfont(xStart + 135, yStart + 110, 40, 90, 0, 0, "宋体", "传动方式:");
                TSCLIB_DLL.windowsfont(xStart + 135, yStart - 110, 40, 90, 2, 0, "黑体", "磁传动");

                xStart = xStart + 50;
                TSCLIB_DLL.windowsfont(xStart + 135, yStart + 110, 40, 90, 0, 0, "宋体", "出厂日期:");
                TSCLIB_DLL.windowsfont(xStart + 135, yStart - 110, 45, 90, 2, 0, "黑体", printInfo.productDate.ToString("yyyyMMdd"));

                yStart = 610 + printInfo.intDist;
                for (int i = 0; i < printInfo.intCount; i++)
                {
                    if (printInfo.strCode[i].Length > 12)
                    {
                        //TSCLIB_DLL.windowsfont(xFont + i * xDist, yStart - 10, fontsize - 20, 90, 2, 0, "黑体", printInfo.strCode[i]);
                        TSCLIB_DLL.barcode(Convert.ToString(xFont + i * xDist), Convert.ToString(yStart - 10), "128", "70", "2", "270", "4", "4", printInfo.strCode[i]);
                    }
                    else
                    {
                        //TSCLIB_DLL.windowsfont(xFont + i * xDist, yStart - 10, fontsize, 90, 2, 0, "黑体", printInfo.strCode[i]);
                        TSCLIB_DLL.barcode(Convert.ToString(xFont + i * xDist), Convert.ToString(yStart - 10), "128", "70", "2", "270", "4", "4", printInfo.strCode[i]);
                    }

                }

                cmdBox = "BOX 360," + Convert.ToString(yStart - 470) + ",850," + Convert.ToString(yStart + 70) + ",2";
                TSCLIB_DLL.sendcommand(cmdBox);

                TSCLIB_DLL.windowsfont(xFont + 5 + 0, yStart + 55, fontsize1, 90, 2, 0, "宋体", "装");
                TSCLIB_DLL.windowsfont(xFont + 5 + xDist, yStart + 55, fontsize1, 90, 2, 0, "宋体", "箱");
                TSCLIB_DLL.windowsfont(xFont + 5 + xDist * 2, yStart + 55, fontsize1, 90, 2, 0, "宋体", "明");
                TSCLIB_DLL.windowsfont(xFont + 5 + xDist * 3, yStart + 55, fontsize1, 90, 2, 0, "宋体", "细");

                //if (printInfo.strCustomer.Length <= 6)
                //{
                //    TSCLIB_DLL.windowsfont(xStart + 540, yStart + 50, 65, 90, 2, 0, "宋体", printInfo.strCustomer);
                //}
                //else
                //{
                //    TSCLIB_DLL.windowsfont(xStart + 540, yStart + 70, 42, 90, 2, 0, "宋体", printInfo.strCustomer);
                //}
                TSCLIB_DLL.windowsfont(xStart + 740, yStart, 42, 90, 2, 0, "宋体", printInfo.strCustomer);

                TSCLIB_DLL.printlabel("1", printInfo.strPrtNum.ToString());

                TSCLIB_DLL.sendcommand("FEED 360");

                TSCLIB_DLL.closeport();
            }
            else
            {
                // 没有传动方式，以前的打印
                int xStart, yStart, xDist, xFont;
                int fontsize, fontsize1;
                string cmdBox;

                fontsize = 52;
                fontsize1 = 45;

                xStart = 100;
                //yStart = 610 + printInfo.intDist;
                xDist = 120;
                xFont = 340;

                TSCLIB_DLL.openport(GlobalVal.ipAddressInfo.PRINTER_NAME);

                TSCLIB_DLL.setup("80", "65", "2", Consts.PRINT_DENSITY, "0", "4", "0");

                TSCLIB_DLL.clearbuffer();

                TSCLIB_DLL.sendcommand("BACKFEED 360");

                yStart = 550 + printInfo.intDist;
                TSCLIB_DLL.barcode(Convert.ToString(xStart - 65), Convert.ToString(yStart+115), "128", "90", "2", "270", "5", "5", printInfo.packCode);
                //TSCLIB_DLL.windowsfont(xStart + 20, yStart + 35, 55, 90, 2, 0, "黑体", printInfo.packCode);

                TSCLIB_DLL.windowsfont(xStart + 80, yStart + 110, 40, 90, 0, 0, "宋体", "型号:");
                TSCLIB_DLL.windowsfont(xStart + 60, yStart, 75, 90, 2, 0, "黑体", printInfo.mType);
                TSCLIB_DLL.windowsfont(xStart + 80, yStart - 230, 35, 90, 0, 0, "宋体", "数量:");
                TSCLIB_DLL.windowsfont(xStart + 60, yStart - 340, 75, 90, 2, 0, "黑体", printInfo.packCount.ToString());

                TSCLIB_DLL.windowsfont(xStart + 145, yStart + 110, 40, 90, 0, 0, "宋体", "出厂日期:");
                TSCLIB_DLL.windowsfont(xStart + 140, yStart - 110, 45, 90, 2, 0, "黑体", printInfo.productDate.ToString("yyyyMMdd"));

                yStart = 610 + printInfo.intDist;
                for (int i = 0; i < printInfo.intCount; i++)
                {
                    if (printInfo.strCode[i].Length > 12)
                    {
                        //TSCLIB_DLL.windowsfont(xFont + i * xDist, yStart - 10, fontsize - 20, 90, 2, 0, "黑体", printInfo.strCode[i]);
                        TSCLIB_DLL.barcode(Convert.ToString(xFont + i * xDist), Convert.ToString(yStart - 10), "128", "70", "2", "270", "4", "4", printInfo.strCode[i]);
                    }
                    else
                    {
                        //TSCLIB_DLL.windowsfont(xFont + i * xDist, yStart - 10, fontsize, 90, 2, 0, "黑体", printInfo.strCode[i]);
                        TSCLIB_DLL.barcode(Convert.ToString(xFont + i * xDist), Convert.ToString(yStart - 10), "128", "70", "2", "270", "4", "4", printInfo.strCode[i]);
                    }

                }

                cmdBox = "BOX 320," + Convert.ToString(yStart - 470) + ",810," + Convert.ToString(yStart + 70) + ",2";
                TSCLIB_DLL.sendcommand(cmdBox);

                TSCLIB_DLL.windowsfont(xFont + 5 + 0, yStart + 55, fontsize1, 90, 2, 0, "宋体", "装");
                TSCLIB_DLL.windowsfont(xFont + 5 + xDist, yStart + 55, fontsize1, 90, 2, 0, "宋体", "箱");
                TSCLIB_DLL.windowsfont(xFont + 5 + xDist * 2, yStart + 55, fontsize1, 90, 2, 0, "宋体", "明");
                TSCLIB_DLL.windowsfont(xFont + 5 + xDist * 3, yStart + 55, fontsize1, 90, 2, 0, "宋体", "细");

                //if (printInfo.strCustomer.Length <= 6)
                //{
                //    TSCLIB_DLL.windowsfont(xStart + 540, yStart + 50, 65, 90, 2, 0, "宋体", printInfo.strCustomer);
                //}
                //else
                //{
                //    TSCLIB_DLL.windowsfont(xStart + 540, yStart + 70, 42, 90, 2, 0, "宋体", printInfo.strCustomer);
                //}
                TSCLIB_DLL.windowsfont(xStart + 740, yStart, 42, 90, 2, 0, "宋体", printInfo.strCustomer);

                TSCLIB_DLL.printlabel("1", printInfo.strPrtNum.ToString());

                TSCLIB_DLL.sendcommand("FEED 360");

                TSCLIB_DLL.closeport();
            }

        }

    }
}
